using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour 
{

	public float Speed = 1;
	public Vector2 Dimensions{ get{ return _dimensions;}}
	public float PlayAreaSize{get{return _playAreaSize;}}
	
	private Vector2 _dimensions;
	private float _playAreaSize = 50;
	private float smooth = 10;
	private Vector3 speedY;
	private Vector3 speedX;

	
	
	// Use this for initialization
	void Start () 
	{
		_dimensions = new Vector2(PlayAreaSize,PlayAreaSize);
		speedY = new Vector3(0,Speed,0);
		speedX = new Vector3(Speed,0,0);
		transform.position = new Vector3(PlayAreaSize*0.5f,PlayAreaSize*0.5f,0);
		//Fix the standart rotation here kk thx!
		//transform.rotation = new Quaternion(90,-180,0,0);
	}
	

	void Update () 
	{
		Controller();
		if(Input.GetButton ("Fire1"))
		{
			GetComponentInChildren<MiniGun>().Fire();
		}
			
	}
	
	private void Controller()
	{

		#region Controlls
			//Up
			if(Input.GetKey(KeyCode.W))
			{
				float toBeClamped = Mathf.Clamp (this.transform.position.y + speedY.y, 0, Dimensions.y);
				Vector3 futurePosition = new Vector3(transform.position.x, toBeClamped, 0);
				transform.position = Vector3.Lerp (this.transform.position, futurePosition, smooth * Time.deltaTime);;
			}
			
			//Down
			if(Input.GetKey (KeyCode.S))
			{
				Vector3 futurePosition = new Vector3(transform.position.x, Mathf.Clamp (this.transform.position.y -speedY.y, 0 , Dimensions.y), 0);
				transform.position = Vector3.Lerp (this.transform.position,futurePosition , smooth * Time.deltaTime);
			}
			
			//Left
			if(Input.GetKey (KeyCode.A))
			{
				Vector3 futurePosition = new Vector3(Mathf.Clamp (this.transform.position.x -speedX.x, 0 , Dimensions.x),transform.position.y, 0);
				transform.position = Vector3.Lerp (this.transform.position,futurePosition, smooth * Time.deltaTime);
				
			}
			
			//Right
			 if(Input.GetKey (KeyCode.D))
			{
				Vector3 futurePosition = new Vector3(Mathf.Clamp (this.transform.position.x + speedX.x, 0, Dimensions.x),transform.position.y, 0);
				transform.position = Vector3.Lerp (this.transform.position,futurePosition, smooth * Time.deltaTime);
			}
		#endregion
	}
	
}
